<template>
  <el-dialog v-dialogDrag v-if="popenevTVisible" title="附件" :close-on-click-modal="false" :before-close="handleCancel" :visible.sync="popenevTVisible" width="900px">
    <AttachmentList ref="attachmentListRef" :isTable="true" :isRead="isRead" :hiddenDelete="isRead"></AttachmentList>
  </el-dialog>
</template>

<script setup>
import { ref, nextTick } from 'vue';
import AttachmentList from "../AttachmentList.vue";

// 响应式数据
const popenevTVisible = ref(true);
const promiseStatus = ref(null);
const isRead = ref(false);
const attachmentListRef = ref(null);

// 方法
const showModal = (data) => {
    isRead.value = data.isRead;
    nextTick(() => {
        // 获取附件数据
        attachmentListRef.value.getTableData(data);
    });
    
    // 创建promise
    return new Promise((resolve, reject) => {
        promiseStatus.value = {
            resolve,
            reject
        };
    });
};

const handleCancel = () => {
    promiseStatus.value.reject();
    destroyElement();
};

const destroyElement = () => {
    popenevTVisible.value = false;
};

// 导出方法
defineExpose({
    showModal
});
</script>